<?php

namespace App\Remote\HuaweiPush;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class HuaweiPushRemote extends Remote
{

    /**
     * @param array $tokens
     * @param string $title
     * @param string $body
     * @param string $path
     * @param array $extra
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function tokensMultiPush(array $tokens, string $title, string $body, string $path, array $extra)
    {
        $clientId = config("push.huawei.clientId");
        return self::customRequestV3(
            "/v1/{$clientId}/messages:send",
            RequestAlias::METHOD_POST,
            [
                "validate_only" => false,
                "message"       => [
                    "android" => [
                        "category"     => "WORK",
                        "data"         => json_encode([
                            "kf" => array_merge(["path" => $path], $extra)
                        ], JSON_UNESCAPED_UNICODE),
                        "notification" => [
                            "title"        => $title,
                            "body"         => $body,
                            "click_action" => [
                                "type" => 3
                            ]
                        ]
                    ],
                    "token"   => $tokens
                ]
            ]
        );
    }
}
